package message

import (
	"common/mildware"
	"common/models"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func (h MHandler) SearchByForm(c *gin.Context) {
	resp := new(models.RespData)
	//token
	ID, _, _, err := mildware.GetCyrrentUserID(c)
	if err != nil {
		resp.SendServerBusy(c)
		return
	}
	page, size, err := models.GetPageInfo(c)
	if err != nil {
		zap.L().Error("Message: SearchByForm  models.GetPageInfo", zap.Error(err))
		resp.SendServerBusy(c)
		return
	}
	from, total, err := h.M.MessageSearchByFrom(ID, page, size)
	if err != nil {
		zap.L().Error("Message: SearchByForm   h.M.MessageSearchByFrom", zap.Error(err))
		resp.SendServerBusy(c)
		return
	}
	resp.Data = from
	resp.Count = total
	resp.SendSuccess(c)
}
func (h MHandler) SearchByTo(c *gin.Context) {
	resp := new(models.RespData)
	//token
	ID, _, _, err := mildware.GetCyrrentUserID(c)
	if err != nil {
		resp.SendServerBusy(c)
		return
	}
	page, size, err := models.GetPageInfo(c)
	if err != nil {
		zap.L().Error("Message: SearchByForm  models.GetPageInfo", zap.Error(err))
		resp.SendServerBusy(c)
		return
	}
	from, total, err := h.M.MessageSearchByTo(ID, page, size)
	if err != nil {
		zap.L().Error("Message: SearchByForm   h.M.MessageSearchByTo", zap.Error(err))
		resp.SendServerBusy(c)
		return
	}
	resp.Data = from
	resp.Count = total
	resp.SendSuccess(c)
}
